class DateTool {


    static getMinutes(): number {// 获取当前分钟
        var d = new Date(new Date());
        var hour = 60;//1小时
        var day = 24 * hour;//1天
        var totalDay = DateTool.mGetDate() - 1;//共多少天
        var totalHour = DateTool.digit(d.getHours());
        var totalMinutes = DateTool.digit(d.getMinutes());
        return totalDay * day + parseInt(totalHour) * hour + parseInt(totalMinutes);
    }

    static getDate() {// 获取日期
        var d = new Date(new Date());
        return d.getFullYear() + '-' + DateTool.digit(d.getMonth() + 1) + '-' + DateTool.digit(d.getDate())
            + ' ' + DateTool.digit(d.getHours()) + ':' + DateTool.digit(d.getMinutes()) + ':' + DateTool.digit(d.getSeconds());
    }
    static digit(num: number): string {//补齐数位
        return num < 10 ? '0' + (num | 0) : ""+ num;
    }
    static getTimeText(time: string) : string{// 

        if (!time) {
            return '';
        }
        var timeS = time;
        var todayT = 0; //
        var yestodayT = 0;
        var d = new Date(new Date());
        var year = 0;
        var month = 0;
        var day = 0;
        var timeCha = DateTool.getTimeS(timeS);
        timeS = timeS.slice(-8);
        year = ~~time.slice(0, 4);
        month = ~~time.slice(5, 7);
        day = ~~time.slice(8, 10);
        todayT = ~~DateTool.digit(d.getHours()) * 60 * 60 * 1000 + ~~DateTool.digit(d.getMinutes()) * 60 * 1000 + ~~DateTool.digit(d.getSeconds()) * 1000;
        yestodayT = todayT + 24 * 60 * 60 * 1000;
        if (timeCha > yestodayT) {
            if (year < d.getFullYear()) {
                return ~~timeS.slice(0, 2) > 12 ? year + '年' + month + '月' + day + '日' + ' 下午' + (~~timeS.slice(0, 2) == 12 ? 12 : ~~timeS.slice(0, 2) - 12) + timeS.slice(2, 5) : year + '年' + month + '月' + day + '日' + ' 上午' + timeS.slice(0, 5);
            } else {
                return ~~timeS.slice(0, 2) > 12 ? month + '月' + day + '日' + ' 下午' + (~~timeS.slice(0, 2) == 12 ? 12 : ~~timeS.slice(0, 2) - 12) + timeS.slice(2, 5) : month + '月' + day + '日' + ' 上午' + timeS.slice(0, 5);
            }

        }
        if (timeCha > todayT && timeCha < yestodayT) {
            return '昨天 ' + timeS.slice(0, 5);
        }
        if (timeCha < todayT) {
            return timeS.slice(0, 5);
        }

        return '';
    }

    static mGetDate() {// 获取天数
        return Math.ceil((new Date().getTime() - new Date(new Date().getFullYear().toString()).getTime()) / (24 * 60 * 60 * 1000)) + 1;
    }
    static getTimeS(arg: string) {// 日期转时间戳
        console.log(arg);
        var timeS = arg;
        timeS = timeS.replace(/[年月]/g, '/').replace(/[日]/, '');
        return new Date().getTime() - new Date(timeS).getTime() - 1000; //有一秒的误差
    }
}

export default DateTool;